package test;

import java.util.Stack;

public class Solution {
    public static void main(String[] args) {
        int m = 100;
        int n = 4;

        Stack<Integer> a = new Stack<Integer>();
        Stack<Integer> b = new Stack<Integer>();


        for (int i = m; i > 0; i--) {
            a.push(i);
        }
        int count = m;
        int times = 1;
        do {//交互出栈顺序
            if (a.size() == 0) {
                while (b.size() != 0) {
                    a.push(b.pop());
                }
                continue;
            } else if (times == n) {
                times = 1;
                a.pop();
                count--;
            } else {
                b.push(a.pop());
                times++;
            }
        } while (count != 1);
        System.out.println(a);
        System.out.println(b);
    }
}

